home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 6623 / 6623.xpi / content / bp.js next >
Text File  |  2010-01-05  |  49KB  |  1,530 lines

  1.  
  2.  
  3.  
  4. var bpriv = {
  5.     prompts: Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService),
  6.     wm: Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator),
  7.     prefs: Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.bprivacy."),
  8.     mw: window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
  9.                            .getInterface(Components.interfaces.nsIWebNavigation)
  10.                            .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
  11.                            .rootTreeItem
  12.                            .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
  13.                            .getInterface(Components.interfaces.nsIDOMWindow),
  14.     nsIFilePicker: Components.interfaces.nsIFilePicker,
  15.     lsos: [],
  16.     Stack: [],
  17.     timerID: 0,
  18.     tStart: null,
  19.     tTicks: null,
  20.     selected: null,
  21.     Scan: 0,
  22.  
  23.  
  24.     LOG: function(text)
  25.     {
  26.         var consoleService = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
  27.         consoleService.logStringMessage(text);
  28.     },
  29.  
  30.  
  31.     WindowOnEnter: function(event) {
  32.         if (event.keyCode == 13) { return false; }
  33.         return true;
  34.     },
  35.  
  36.  
  37.     openHelp: function()
  38.     {
  39.         if(gBrowser)
  40.             gBrowser.selectedTab = gBrowser.addTab('chrome://bp/content/bphelp.html'); 
  41.     },
  42.  
  43.  
  44.     getDoc: function()
  45.     {
  46.         var doc = bpriv.mw.document;
  47.         if(!doc)
  48.             doc = window.document;
  49.         return doc;
  50.     },
  51.  
  52.  
  53.  
  54.  
  55.     convert: function()
  56.     {
  57.         var PrefSrv = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  58.         //AutoDelLSO
  59.         try{
  60.             //if( !navigator.preference("extensions.bprivacy.version") || parseInt(navigator.preference("extensions.bprivacy.version")) < 139)
  61.             if(navigator.preference("extensions.bprivacy.AutoDelLSO") == false) 
  62.                 navigator.preference("extensions.bprivacy.AutoDelLSOnExitMode", 1);
  63.             PrefSrv.clearUserPref("extensions.bprivacy.AutoDelLSO"); //delete preference
  64.         }catch(e){}
  65.         //FlashAppDir
  66.         try{
  67.             if(navigator.preference("extensions.bprivacy.flashAppDir") && String(navigator.preference("extensions.bprivacy.flashAppDir")).length)
  68.             {
  69.                 var Dir = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  70.                   Dir.initWithPath(navigator.preference("extensions.bprivacy.flashAppDir"));
  71.                   if(Dir.path && Dir.exists() && Dir.isDirectory())
  72.                     bpriv.prefs.setComplexValue("DataDir", Components.interfaces.nsILocalFile, Dir);
  73.             }
  74.             PrefSrv.clearUserPref("extensions.bprivacy.flashAppDir"); //delete preference
  75.         }catch(e){}
  76.         //DOMStorage
  77.         try{
  78.             if(navigator.preference("extensions.bprivacy.domstorage.allowed") == false )
  79.             {
  80.                 navigator.preference("extensions.bprivacy.domclear", true);
  81.                 navigator.preference("dom.storage.enabled", true);
  82.                 PrefSrv.clearUserPref("extensions.bprivacy.domstorage.allowed"); //delete preference
  83.             }
  84.         }catch(e){}
  85.  
  86.     },
  87.  
  88.  
  89.  
  90.     //startup of FireFox
  91.     firstload: function(event)
  92.     {
  93.         //debug
  94.         //navigator.preference("javascript.options.showInConsole", true);
  95.         bpriv.convert();
  96.         if(!navigator.preference("extensions.bprivacy.initiated"))
  97.         {
  98.             navigator.preference("extensions.bprivacy.initiated", true);
  99.             navigator.preference("browser.send_pings", false);
  100.             navigator.preference("extensions.bprivacy.sendpings.allowed", false);
  101.             bpriv.GetFlashDir(2);//set flashApp directory preference, scan if necessary
  102.             setTimeout("bpriv.openHelp()", 25000);
  103.         }else
  104.         {
  105.             if(navigator.preference("extensions.bprivacy.alwaysReScan") || !bpriv.GetFlashDir(0))
  106.                 bpriv.GetFlashDir(1);
  107.         }
  108.         if( 
  109.             ( !navigator.preference("extensions.bprivacy.sendpings.allowed") && (navigator.preference("extensions.bprivacy.sendpings.allowed") != navigator.preference("browser.send_pings")) )
  110.         )
  111.         {
  112.             if(confirm("BetterPrivacy:\r\nThe extension detected that one or more privacy settings have been modified!\r\nPress OK to correct those values.")){
  113.                 navigator.preference("browser.send_pings", navigator.preference("extensions.bprivacy.sendpings.allowed"));
  114.             }
  115.         }
  116.         if(navigator.preference("extensions.bprivacy.DelTimerInterval") < 1)
  117.             navigator.preference("extensions.bprivacy.DelTimerInterval", 1);
  118.  
  119.         if(window == bpriv.mw)
  120.         {
  121. ////            window.addEventListener("unload", bpriv.onexit, false); 
  122.             if(navigator.preference("extensions.bprivacy.domclear")){
  123.                 bpriv.DelDOM();
  124.             }//AutoDelDOM
  125.             if(navigator.preference("extensions.bprivacy.AutoDelLSOnStart"))
  126.                 bpriv.prepareDelLSO(2, null);
  127.             bpriv.startDelTimer();
  128.         }
  129.         bpriv.SetKeys();
  130.         navigator.preference("extensions.bprivacy.version", String(bpriv.getVersion()).replace(/\./, ""));
  131.         bpriv.setPropagation();
  132.     },//end menue load
  133.  
  134.  
  135.     setPropagation: function()
  136.     {
  137.         if(navigator.preference("extensions.bprivacy.propagate"))
  138.             navigator.preference("general.useragent.extra.betterprivacy", "BetterPrivacy-" + bpriv.getVersion());
  139.         else
  140.             navigator.preference("general.useragent.extra.betterprivacy", "");
  141.     },
  142.  
  143.  
  144.  
  145.     getVersion: function()
  146.     {
  147.         return Components.classes["@mozilla.org/extensions/manager;1"].getService(Components.interfaces.nsIExtensionManager)
  148.                         .getItemForID("{d40f5e7b-d2cf-4856-b441-cc613eeffbe3}").version;
  149.     },
  150.  
  151.  
  152.     SetKeys: function()
  153.     {
  154.         var kNode = document.getElementById("key_bp");
  155.         if(kNode)
  156.         {
  157.             var keyCode = navigator.preference("extensions.bprivacy.keycode");
  158.             if(keyCode){
  159.                 kNode.setAttribute("disabled", false);
  160.                 kNode.setAttribute("modifiers", String(navigator.preference("extensions.bprivacy.keymodifiers")));
  161.                 kNode.setAttribute("key", String.fromCharCode(keyCode));
  162.             }
  163.         }
  164.     },
  165.  
  166.  
  167.  
  168.  
  169.  
  170.     GetDirs: function(currentDir, dirArray)
  171.     {
  172.         var entries;
  173.         try{
  174.             entries = currentDir.directoryEntries;
  175.         }catch(e){}
  176.         while(entries && entries.hasMoreElements())
  177.         {
  178.             var entry = entries.getNext();
  179.             try{
  180.                 entry.QueryInterface(Components.interfaces.nsIFile);
  181.                 if (entry.isDirectory() && !entry.isSymlink() && !bpriv.isSpecial(entry))
  182.                 {
  183.                     dirArray.push(entry);
  184.                     bpriv.GetDirs(entry, dirArray);
  185.                 }
  186.             }catch(e){bpriv.LOG("BetterPrivacy: Failure parsing directories - " + e);}
  187.         }
  188.         return dirArray;
  189.     },
  190.  
  191.  
  192.  
  193.  
  194.     DelDirSortAlgo: function(file1, file2)
  195.     {
  196.             if (file1.path.length > file2.path.length)
  197.             return -1;
  198.             else if (file2.path.length > file1.path.length)
  199.             return 1;
  200.             return 0;
  201.     },
  202.  
  203.  
  204.  
  205.     delDirs: function(FlashDirRoot)
  206.     {
  207.         if(!FlashDirRoot || !navigator.preference("extensions.bprivacy.delDirs"))
  208.             return;
  209.           // Delete ISO8601 formated directories 
  210.         var dirArray = new Array();
  211.         bpriv.GetDirs(FlashDirRoot, dirArray);
  212.         var numDirsToDelete = dirArray.length;
  213.         dirArray.sort(bpriv.DelDirSortAlgo);
  214.         for(var i=0; i<numDirsToDelete; i++)
  215.         {
  216.             try{ //never delete non-empty directories (FF throws NS_ERROR_FILE_DIR_NOT_EMPTY if remove attribut is false)
  217.                 dirArray[i].remove(false);
  218.             }catch(e)
  219.             {
  220.                 if(e.name != "NS_ERROR_FILE_DIR_NOT_EMPTY")
  221.                     bpriv.LOG("BetterPrivacy: Unable to delete directory (usually due to an open handle or missing permission)- " + dirArray[i].path + " - " + e);
  222.             }
  223.         }
  224.         dirArray = null;
  225.     },
  226.  
  227.  
  228.  
  229.     onexit: function(event)
  230.     {
  231.         ////try{bpriv.mw.removeEventListener("unload", bpriv.onexit, false);}catch(e){} 
  232.         try{
  233.             bpriv.mw.clearTimeout(bpriv.timerID);
  234.             var enumerator = bpriv.wm.getEnumerator("navigator:browser");
  235.         /*
  236.         if(enumerator && !enumerator.hasMoreElements()){ //is it not the last window?
  237.             if(navigator.preference("extensions.bprivacy.domclear")){
  238.                 bpriv.DelDOM();
  239.             }//AutoDelDOM
  240.             bpriv.prepareDelLSO(3, null);
  241.         }
  242.         */
  243.  
  244.         var wincount = 0;
  245.         while(enumerator && enumerator.hasMoreElements()){ 
  246.             wincount++;
  247.             enumerator.getNext();
  248.         }
  249.  
  250.         if(wincount == 1){
  251.             if(navigator.preference("extensions.bprivacy.domclear")){
  252.                 bpriv.DelDOM();
  253.             }//AutoDelDOM
  254.             bpriv.prepareDelLSO(3, null);
  255.         }
  256.  
  257.         }catch(e){alert("BetterPrivacy\r\nError on exit\r\nPlease report this to the author " + e);}
  258.  
  259.     //When a string is assigned to the returnValue property of window.event, a dialog box appears....
  260.     //the problem seems to be:
  261.     //1. when onbeforeunload is called, it will take the return value of the handler as window.event.returnValue.
  262.     //2. it will then parse the return value as a string (unless it is null)
  263.     //3. since false is parsed as a string, the dialogue box will fire, which will then pass an appropriate true/false
  264.     //the result is, there doesn't seem to be a way of assigning false to onbeforeunload, to prevent it from the default dialogue.
  265.  
  266.     //    return true;
  267.     },
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.     DelDOM: function()
  275.     {
  276.         var file = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile);
  277.         file.append("webappsstore.sqlite");
  278.  
  279.         if(file.exists()) // if it exists, delete
  280.         {   
  281.             try{
  282.                 file.remove(false);
  283.             }catch(e){
  284.                 bpriv.LOG("BetterPrivacy: Deletion of DOM data currently impossible due to open handle - trying again later.");
  285.             }
  286.         }
  287.     },
  288.  
  289.  
  290.     checkFlashFolder: function()
  291.     {
  292.         if (!bpriv.GetFlashDir(0))
  293.         {
  294.             if (!navigator.preference("extensions.bprivacy.donotaskforfolder"))
  295.             {
  296.                 check = {value: false};
  297.                 var confirmed = bpriv.prompts.confirmCheck(window, "BetterPrivacy", bpriv.getString("askfornewpath"), bpriv.getString("askfornewpath2"), check);
  298.                 navigator.preference("extensions.bprivacy.donotaskforfolder", check.value);
  299.                 if(confirmed)
  300.                     window.openDialog('chrome://bp/content/bp.xul', '_blank', 'chrome=yes, modal=yes, resizable=yes, centerscreen=yes');
  301.             }
  302.         }
  303.         return bpriv.GetFlashDir(0);
  304.     },
  305.  
  306.  
  307.  
  308.  
  309.  
  310.     LSOtoDelete: function() 
  311.     {
  312.         bpriv.lsos = [];
  313.         if(!bpriv.checkFlashFolder())
  314.             return 0;
  315.  
  316.         bpriv.LoadLsos(bpriv.GetFlashDir(0), true); 
  317.         var deleted = 0;
  318.         for (var x=0;x<bpriv.lsos.length;x++)//first check number of LSO's to be deleted
  319.         {
  320.             try{
  321.                 var defaultCookie = false;
  322.                 var protectedCookie = false;
  323.                 if(String(bpriv.lsos[x].prot).indexOf("d") >= 0 || String(bpriv.lsos[x].prot).indexOf("s") >= 0)
  324.                     protectedCookie = true;
  325.                 var dir = String(bpriv.lsos[x].path).replace(/settings\.sol/, "");
  326.                 var regex = new RegExp(navigator.preference("extensions.bprivacy.DefaultLSORegEx"), 'i');
  327.                 if( bpriv.lsos[x].file.leafName.toLowerCase() == navigator.preference("extensions.bprivacy.DefaultLSOName") && dir.match(regex))
  328.                     defaultCookie = true;
  329.                 if(!protectedCookie && (!defaultCookie || navigator.preference("extensions.bprivacy.DefaultFlashCookieDeletion")))
  330.                     deleted++;
  331.             }catch(e){bpriv.LOG("BetterPrivacy: Error while counting LSOs");}
  332.         }
  333.         return deleted;
  334.  
  335.     },
  336.  
  337.  
  338.  
  339.  
  340.  
  341.     prepareDelLSO: function(mode, trange)  //mode 1=byTimer 2=onStartup 3=onExit
  342.     {
  343.         try{
  344.             if(mode == 3)
  345.             {
  346.                 if(navigator.preference("extensions.bprivacy.AutoDelLSOnExitMode") == 0)
  347.                 {
  348.                     if(!navigator.preference("extensions.bprivacy.donotaskonexit"))
  349.                     {
  350.                         window.openDialog("chrome://bp/content/progress.xul", "_blank", "chrome=yes, modal=yes, resizable=no, centerscreen=yes, alwaysRaised=yes", mode);
  351.                     }else
  352.                     {
  353.                         if(bpriv.LSOtoDelete())
  354.                             bpriv.DelLSO(mode, trange);
  355.                     }
  356.                 }
  357.                 else if(navigator.preference("extensions.bprivacy.AutoDelLSOnExitMode") == 1)
  358.                 {
  359.                         if(!navigator.preference("privacy.item.extensions-betterprivacy"))
  360.                             return;
  361.                         if(bpriv.LSOtoDelete())
  362.                             bpriv.DelLSO(mode, trange);
  363.                 }
  364.             }else
  365.             {
  366.                 if(bpriv.LSOtoDelete())
  367.                     bpriv.DelLSO(mode, trange);
  368.             }
  369.         }catch(e){alert("BetterPrivacy: Error in prepare delete LSO function: " + e);}
  370.     },
  371.  
  372.  
  373.  
  374.  
  375.     processProgressWindow: function(win, mode) //always mode 3
  376.     {
  377.         var deleted = bpriv.LSOtoDelete();
  378.         //win.close();
  379.         if(deleted)
  380.         {
  381.             check = {value: false};
  382.             var delconfirmed = bpriv.prompts.confirmCheck(window, bpriv.getString("askfordeletion1"), bpriv.getString("askfordeletion2") + " " + deleted + " " + bpriv.getString("askfordeletion3"), bpriv.getString("askfordeletion4"), check);
  383.             navigator.preference("extensions.bprivacy.donotaskonexit", check.value);
  384.             if(delconfirmed)
  385.                 bpriv.DelLSO(mode, null);
  386.         }
  387.         win.close();//keep open until here, else the processing might be aborted before finishing
  388.     },
  389.  
  390.  
  391.     DelLSO: function(mode, range)//mode 0=ClearHistory 1=byTimer 2=onStartup 3=onExit
  392.     {
  393.         try{
  394.             deleted = 0;
  395.             for (var x=0;x<bpriv.lsos.length;x++)//effectively delete LSO's
  396.             {
  397.                 try{
  398.                     var defaultCookie = false;
  399.                     var protectedCookie = false;
  400.                     if(String(bpriv.lsos[x].prot).indexOf("d") >= 0 || String(bpriv.lsos[x].prot).indexOf("s") >= 0)
  401.                         protectedCookie = true;
  402.                     var dir = String(bpriv.lsos[x].path).replace(/settings\.sol/, "");
  403.                     var regex = new RegExp(navigator.preference("extensions.bprivacy.DefaultLSORegEx"), 'i');
  404.                     if( bpriv.lsos[x].file.leafName.toLowerCase() == navigator.preference("extensions.bprivacy.DefaultLSOName") && dir.match(regex))
  405.                         defaultCookie = true;
  406.                     if(!protectedCookie && (!defaultCookie || navigator.preference("extensions.bprivacy.DefaultFlashCookieDeletion")))
  407.                     {
  408.                             var cDate = new Date();
  409.                             if( mode == 1 && navigator.preference("extensions.bprivacy.useDelTimerDelay") && cDate.getTime() >= bpriv.lsos[x].file.lastModifiedTime && cDate.getTime()-bpriv.lsos[x].file.lastModifiedTime < navigator.preference("extensions.bprivacy.DelTimerInterval") * 1000 )
  410.                                 continue;
  411.                             if( mode == 0 && range && cDate.getTime() >= bpriv.lsos[x].file.lastModifiedTime && cDate.getTime()-bpriv.lsos[x].file.lastModifiedTime > range )
  412.                                 continue;
  413.                             bpriv.lsos[x].file.remove(false);
  414.                             deleted++;
  415.                     }
  416.                 }catch(e){bpriv.LOG("BetterPrivacy: Error while deleting LSO");}
  417.             }
  418.             navigator.preference("extensions.bprivacy.removed", navigator.preference("extensions.bprivacy.removed") + deleted);//statistics
  419.             navigator.preference("extensions.bprivacy.removedSession", navigator.preference("extensions.bprivacy.removedSession") + deleted);//statistics
  420.             bpriv.delDirs(bpriv.GetFlashDir(0)); //remove folders
  421.             bpriv.updateKnownLSOs();
  422.         }catch(e){alert("BetterPrivacy: Error in delete LSO function: " + e);}
  423.     },
  424.  
  425.  
  426.     updateKnownLSOs: function() 
  427.     {
  428.         if(bpriv.lsos)
  429.             navigator.preference("extensions.bprivacy.LSOcount", bpriv.lsos.length);
  430.     },
  431.  
  432.  
  433.  
  434.  
  435.     modifiedSince: function(lso) 
  436.     {
  437.         var c = new Date(); //will hold current ticks
  438.         var m = new Date();
  439.         m.setTime(parseInt(lso.modified)); //modified lso ticks
  440.         var diff = c.getTime() - m.getTime();
  441.         return diff;
  442.     },
  443.  
  444.  
  445.     startDelTimer: function() 
  446.     {
  447.         bpriv.tStart = new Date();
  448.         bpriv.updateDelTimer(true);
  449.     },
  450.  
  451.  
  452.  
  453.     stopDelTimer: function() 
  454.     {
  455.         if(bpriv.timerID) {
  456.             clearTimeout(bpriv.timerID);
  457.             bpriv.timerID  = 0;
  458.         }
  459.         bpriv.tStart = null;
  460.     },
  461.  
  462.  
  463.  
  464.     updateDelTimer: function(initiated) 
  465.     {
  466.         if (FlashDirRoot = bpriv.GetFlashDir(0))
  467.         {
  468.             if(navigator.preference("extensions.bprivacy.NotifyOnNewLSO"))
  469.             {
  470.                 bpriv.lsos = [];
  471.                 bpriv.LoadLsos(FlashDirRoot, false); 
  472.                 if(!initiated && navigator.preference("extensions.bprivacy.NotifyOnNewLSO") == 1 && bpriv.lsos.length > navigator.preference("extensions.bprivacy.LSOcount"))
  473.                 {
  474.                     var count = bpriv.lsos.length - navigator.preference("extensions.bprivacy.LSOcount");
  475.                     var str = count > 1 ? " LSO's have" : " LSO has";
  476.                     var message = "BetterPrivacy detected that " + count + str + " been placed on your harddisk!";
  477.                     bpriv.NotifyNewLSO(bpriv.hashString(message), message);
  478.                 }else
  479.                     navigator.preference("extensions.bprivacy.NotifyOnNewLSO", 1);
  480.                 bpriv.updateKnownLSOs();
  481.             }
  482.         }
  483.         if(bpriv.timerID) 
  484.             clearTimeout(bpriv.timerID);
  485.         if(!bpriv.tStart)
  486.             bpriv.tStart = new Date();
  487.         var tDate = new Date();
  488.         tDate.setTime(tDate.getTime() - bpriv.tStart.getTime());
  489.         if(tDate.getTime() / (navigator.preference("extensions.bprivacy.DelTimerInterval") * 1000) >= 1){
  490.             if(navigator.preference("extensions.bprivacy.useDelTimer"))
  491.                 bpriv.prepareDelLSO(1, null);
  492.             bpriv.tStart = null;
  493.         }
  494.         bpriv.timerID = setTimeout("bpriv.updateDelTimer()", 1000);
  495.     },
  496.  
  497.  
  498.     sortMultiDimensional: function (a,b)
  499.     {
  500.         // this sorts the array using the second element    
  501.         return ((a[1] < b[1]) ? -1 : ((a[1] > b[1]) ? 1 : 0));
  502.     },
  503.  
  504.  
  505.     NotifyNewLSO: function(value, message)
  506.     {
  507.         var c = new Date();
  508.         var mins = c.getMinutes();
  509.         if(mins < 10)
  510.             mins = "0" + mins;
  511.         var secs = c.getSeconds();
  512.         if(secs < 10)
  513.             secs = "0" + secs;
  514.         var ModifiedLSOs = "    Timestamp: " + c.getHours() + ":" + mins + ":" + secs;
  515.         var count = 0;
  516.         for (var x=0;x<bpriv.lsos.length;x++)
  517.         {
  518.             if(bpriv.modifiedSince(bpriv.lsos[x]) < 2000)
  519.             {
  520.                 if(!count)
  521.                     ModifiedLSOs += '    Last modified:';
  522.                 ModifiedLSOs += ' "' + bpriv.lsos[x].file.leafName + '"';
  523.                 count++;
  524.             }
  525.         }
  526.         bpriv.Notification(value, message + ModifiedLSOs);
  527.     },
  528.  
  529.  
  530.  
  531.     Notification: function(value, message)
  532.     {
  533.         var buttons = [{ label: "View LSOs",
  534.                          callback: function() { bpriv.RemoveNotification(value); bpriv.showBetterPrivacy(); }, 
  535.                          accessKey: null, popup: null }];
  536.         var nbox = window.getBrowser().getNotificationBox();
  537.         nbox.appendNotification(message, value, "chrome://bp/content/pie.png", navigator.preference("extensions.bprivacy.NotifyPriority"), buttons);
  538.         if(navigator.preference("extensions.bprivacy.NotifyDuration"))
  539.             setTimeout(function(){bpriv.RemoveNotification(value)}, navigator.preference("extensions.bprivacy.NotifyDuration") * 1000, value);
  540.     },
  541.  
  542.  
  543.     RemoveNotification: function(value)
  544.     {
  545.         if(item = window.getBrowser().getNotificationBox().getNotificationWithValue(value))
  546.             window.getBrowser().getNotificationBox().removeNotification(item);
  547.     },
  548.  
  549.  
  550.  
  551.  
  552.  
  553.     changeAppDir: function(event)
  554.     {
  555.         bpriv.Scan = -1;
  556.         if (event) 
  557.         {
  558.             if (event.keyCode != 13) 
  559.                 return;
  560.             var newpath = bpriv.getDoc().getElementById("appdir").value; 
  561. //            if (newpath == navigator.preference("extensions.bprivacy.flashAppDir")) 
  562.             var oldDir;
  563.             try{
  564.                 oldDir = bpriv.prefs.getComplexValue("DataDir", Components.interfaces.nsILocalFile);
  565.             }catch(e){}
  566.  
  567.             if (oldDir && newpath == oldDir.path) 
  568.                 return;
  569.             if(!confirm("You changed the FlashApplication folder to: \r\n" + newpath + "\r\nDo you want to apply this modification?"))
  570.             {
  571.                 if (oldDir) 
  572.                     newpath = oldDir.path;
  573.                 else
  574.                     newpath = "";
  575.                 bpriv.getDoc().getElementById("appdir").value = newpath;
  576.             }
  577.             var Dir = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  578.             try{
  579.                   Dir.initWithPath(newpath);
  580.                 newpath = Dir;
  581.                   if(!Dir.path || !Dir.exists() || !Dir.isDirectory())
  582.                     newpath = null;
  583.             }catch(e){newpath = null;}
  584.         }else
  585.         {
  586.             var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(bpriv.nsIFilePicker);
  587.             fp.init(window, bpriv.getString("selectDirTitle"), bpriv.nsIFilePicker.modeGetFolder);
  588.             var rv = fp.show();
  589.             if ((rv != bpriv.nsIFilePicker.returnOK) && (rv != bpriv.nsIFilePicker.returnReplace))
  590.                 return;
  591.             var newpath = fp.file;
  592.         }
  593.         if(newpath)
  594. //            navigator.preference("extensions.bprivacy.DataDir", newpath);
  595.             bpriv.prefs.setComplexValue("DataDir", Components.interfaces.nsILocalFile, newpath);
  596.         bpriv.LSOTreeShow(newpath);
  597.         return true;
  598.     },
  599.  
  600.  
  601.  
  602.     searchDir: function()
  603.     {
  604.  
  605.         if(bpriv.getDoc().getElementById("searchFolderID").label != bpriv.getString("abort")){
  606.             if(FlashDir = bpriv.GetFlashDir(2))
  607.                 bpriv.LSOTreeShow(FlashDir);
  608.         }else{
  609.             bpriv.Scan = -1;
  610.         }
  611.     },
  612.  
  613.  
  614.  
  615.     treeView:
  616.     {
  617.         treeBox: null,  
  618.         selection: null, 
  619.         get rowCount()                       { return bpriv.lsos.length; }, 
  620.         setTree: function(treeBox)         { this.treeBox = treeBox; },  
  621.         isSeparator: function(idx)         { return false; },  
  622.         isSorted: function()               { return false; },  
  623.         isEditable: function(idx, column)  { return false; },
  624.         getCellProperties: function(idx, column, prop) {},  
  625.         getColumnProperties: function(column, element, prop) {},  
  626.         getRowProperties: function(row, element, prop) {},  
  627.         getImageSrc: function() {return null;}, 
  628.         isContainer: function() {return false;}, 
  629.         cycleHeader: function() {}, 
  630.          getCellText: function(idx, column)
  631.         {
  632.             if(!bpriv.lsos.length)
  633.                 return "";
  634.             //else if (column.id=="folder")
  635.             else if (column.id=="ident")
  636.                 return bpriv.lsos[idx].ident;
  637.             else if (column.id=="name")
  638.                 return bpriv.lsos[idx].file.leafName;
  639.             else if (column.id=="size")
  640.                 return bpriv.lsos[idx].size;
  641.             else if (column.id=="modified")
  642.             {
  643.                 var cDate = new Date();
  644.                 cDate.setTime(parseInt(bpriv.lsos[idx].modified));
  645.                 return cDate.toLocaleString();
  646.             }
  647.             else if (column.id=="prot")
  648.             {
  649.                 if(bpriv.lsos[idx].prot.indexOf("d") < 0 && bpriv.lsos[idx].prot.indexOf("s") < 0)
  650.                     return bpriv.getString("unprotected");
  651.                 else if(bpriv.lsos[idx].prot.indexOf("d") >= 0)
  652.                     return bpriv.getString("protectedFolder");
  653.                 else if(bpriv.lsos[idx].prot.indexOf("s") >= 0)
  654.                     return bpriv.getString("protectedSubFolder");
  655.             }
  656.             return "";
  657.         },
  658.     },
  659.  
  660.  
  661.  
  662.  
  663.     LSOTreeShow: function(flashDir)
  664.     {
  665.         var cDate = new Date();
  666.         if (!flashDir)
  667.         {
  668.             // Display error if selected directory does not exist
  669.             bpriv.getDoc().getElementById("appdir").setAttribute ("readonly","true");
  670.             bpriv.getDoc().getElementById("appdir").value = bpriv.getString("dirNotFound");
  671.             bpriv.getDoc().getElementById("appdir").style.backgroundColor = "red";
  672.             bpriv.getDoc().getElementById("appdir").style.color = "white";
  673.             bpriv.getDoc().getElementById("searchFolderID").label = bpriv.getString("searchFlashFolder");
  674.             bpriv.getDoc().getElementById("lsoinfo").value = "";
  675.             bpriv.getDoc().getElementById("tip").value = "Status " + cDate.toLocaleString();
  676.         }
  677.         else
  678.         {
  679.             bpriv.getDoc().getElementById("appdir").removeAttribute("readonly");
  680.             bpriv.getDoc().getElementById("appdir").value = flashDir.path;
  681.             bpriv.getDoc().getElementById("appdir").style.backgroundColor = "";
  682.             bpriv.getDoc().getElementById("appdir").style.color = "";
  683.             bpriv.getDoc().getElementById("searchFolderID").label = bpriv.getString("searchFlashFolder");
  684.             bpriv.getDoc().getElementById("lsoinfo").value = bpriv.getString("listLSOs");
  685.             bpriv.getDoc().getElementById("tip").value = "Status " + cDate.toLocaleString(); 
  686.         }
  687.         setTimeout(function(){bpriv.LoadLsosIntoTree(flashDir);}, 500, flashDir); //provide time to update GUI
  688.     },
  689.  
  690.  
  691.  
  692.     LoadLsosIntoTree: function(flashDir)
  693.     {
  694.  
  695.         bpriv.lsos = [];
  696.         if (flashDir)
  697.             bpriv.LoadLsos(flashDir, true);
  698.         bpriv.updateGUI(flashDir, true); 
  699.         bpriv.TreeOnSelect(flashDir);
  700.     },
  701.  
  702.  
  703.  
  704.     ReloadLsos: function()
  705.     {
  706.         bpriv.LSOTreeShow(bpriv.GetFlashDir(0));
  707.     },
  708.         
  709.  
  710.     updateGUI: function(flashDir, sort)
  711.     {
  712.         var LSOTree = bpriv.getDoc().getElementById("LSOViewerTree");
  713.         if(!LSOTree)
  714.             return;
  715.         LSOTree.view = bpriv.treeView;
  716.         bpriv.updateKnownLSOs();
  717.         bpriv.getDoc().getElementById("lso_removed").value = navigator.preference("extensions.bprivacy.removed");
  718.         bpriv.getDoc().getElementById("lso_removedSession").value = navigator.preference("extensions.bprivacy.removedSession");
  719.         bpriv.getDoc().getElementById("removeAllLsos").disabled = bpriv.lsos.length == 0;
  720.         bpriv.getDoc().getElementById("lsoinfo").value = "";
  721.         if(sort)
  722.             bpriv.SortLSOView(null);
  723.         else
  724.             LSOTree.treeBoxObject.invalidate();
  725.     },
  726.  
  727.  
  728.     TreeOnSelect: function(flashDir)
  729.     {
  730.         var LSOTree = bpriv.getDoc().getElementById("LSOViewerTree");
  731.         if(!LSOTree)
  732.             return;
  733.         LSOTree.view = bpriv.treeView;
  734.         if (/*!bpriv.lsos.length ||*/ LSOTree.currentIndex < 0 || !bpriv.lsos[LSOTree.currentIndex])
  735.         {
  736.             bpriv.getDoc().getElementById("FullPathID").value = bpriv.getString("nothingselected");
  737.             bpriv.getDoc().getElementById("protectLsoDir").label = bpriv.getString("protectDir");
  738.             bpriv.getDoc().getElementById("removeLso").disabled = true;
  739.             bpriv.getDoc().getElementById("protectLsoDir").disabled = true;
  740.             return;
  741.         }
  742.         //save selection
  743.         bpriv.selected = bpriv.lsos[LSOTree.currentIndex].path;
  744.         bpriv.getDoc().getElementById("removeLso").removeAttribute("disabled");
  745.         bpriv.getDoc().getElementById("protectLsoDir").removeAttribute("disabled");
  746.         bpriv.getDoc().getElementById("FullPathID").value = bpriv.lsos[LSOTree.currentIndex].path;
  747.         if(bpriv.lsos[LSOTree.currentIndex].prot.indexOf("d") >= 0)
  748.             bpriv.getDoc().getElementById("protectLsoDir").label = bpriv.getString("unprotectDir");
  749.         else
  750.             bpriv.getDoc().getElementById("protectLsoDir").label = bpriv.getString("protectDir");
  751.     },
  752.  
  753.  
  754.  
  755.     getLSOProtection: function(entry)
  756.     {
  757.         var exp = new RegExp(entry.leafName, 'i');
  758.         var dir = entry.path.replace(exp, ""); 
  759.         dir = dir.replace(/[\\\/]$/i, "").toLowerCase();
  760.  
  761.         var prot = "";
  762.         var protListarr = navigator.preference("extensions.bprivacy.protectedLSOList").split("|");
  763.         var exp = new RegExp('^.*'+navigator.preference("extensions.bprivacy.FlashDirRegEx")+'(\u005c\u002f|\u005c\u005c)', 'i');
  764.         if(navigator.preference("extensions.bprivacy.alwaysReScan"))
  765.             dir = dir.replace(exp, "");
  766.         for (var x=0;x<protListarr.length;x++)
  767.         {
  768.             if(!String(protListarr[x]).length)
  769.                 continue;
  770.             var protdir = protListarr[x].toLowerCase();
  771.             if(navigator.preference("extensions.bprivacy.alwaysReScan"))
  772.                 protdir = protdir.replace(exp, "");
  773.             if(dir == protdir){
  774.                 prot = "d";
  775.                 break;
  776.             }else if(navigator.preference("extensions.bprivacy.autosubfolders") && dir.indexOf(protdir) >= 0){
  777.                 prot = "s";
  778.             }
  779.         }
  780.         return prot;
  781.     },
  782.  
  783.  
  784.  
  785.     RefreshLSOProtection: function()
  786.     {
  787.         for (var i=0; i<bpriv.lsos.length; i++)
  788.             bpriv.lsos[i].prot = bpriv.getLSOProtection(bpriv.lsos[i].file);
  789.     },
  790.  
  791.  
  792.  
  793.  
  794.     LoadLsos: function(currentDir, doFootprint)
  795.     {
  796.         //bpriv.LOG("Checking folder for LSOs: " + currentDir.path);
  797.         var protListarr = navigator.preference("extensions.bprivacy.protectedLSOList").split("|");
  798.         var entries; 
  799.         try{
  800.             entries = currentDir.directoryEntries;
  801.         }catch(e){}
  802.         if(!entries)
  803.             bpriv.LOG("BetterPrivacy Warning: A LSO folder is inaccessable: " + currentDir.path);
  804.         while(entries && entries.hasMoreElements())
  805.         {
  806.             try{
  807.                 var entry = entries.getNext();
  808.                 entry.QueryInterface(Components.interfaces.nsIFile);
  809.                 if (entry.isFile() && !entry.isSymlink() && !bpriv.isSpecial(entry))
  810.                 {
  811.                     try{
  812.                         if (bpriv.isLSO(entry, doFootprint))
  813.                         {
  814.                             var cDate = new Date();
  815.                             var ticks = cDate.getTime();
  816.                             var modified = ticks-entry.lastModifiedTime;
  817.                             var prot = bpriv.getLSOProtection(entry);
  818.  
  819.                             var exp = new RegExp('^.*'+navigator.preference("extensions.bprivacy.FlashDirRegEx"), 'i');
  820.                             var ident = entry.path.replace(exp, ""); 
  821.                             exp = new RegExp('^.*'+navigator.preference("extensions.bprivacy.DefaultLSORegEx"), 'i');
  822.                             ident = String(ident).replace(exp, ""); 
  823.                             ident = String(ident).match(/[^\\\/]+\.[^\\\/]+/, ""); 
  824.                             ident = String(ident).replace(/^[#]/, ""); 
  825.                             bpriv.lsos[bpriv.lsos.length] = new bpriv.Lso( entry, /*entry.parent.leafName*/ ident, entry.fileSize, entry.path, prot, String(ticks - modified));
  826.                         }
  827.                     }catch(e){bpriv.LOG("BetterPrivacy: An error occured while scanning folders for LSO data" + e);}
  828.                 }
  829.                 else if (entry.isDirectory() && !entry.isSymlink() && !bpriv.isSpecial(entry)){
  830.                     bpriv.LoadLsos(entry, doFootprint);
  831.                 }
  832.             }catch(e){bpriv.LOG("BetterPrivacy: Error while scanning folders for LSO data" + e);}
  833.         }
  834.         protListarr = null;
  835.     },
  836.  
  837.  
  838.  
  839.     isLSO: function(item, doFootprint)
  840.     {
  841.         var str; 
  842.         var dotIndex  = item.leafName.lastIndexOf('.');
  843.         var extension = (dotIndex >= 0) ? item.leafName.substring(dotIndex+1) : "";
  844.         if(extension.toLowerCase() != navigator.preference("extensions.bprivacy.LSOExtension").toLowerCase())
  845.             return false;
  846.         if(doFootprint)
  847.         {
  848.             var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  849.             try{
  850.                 file.initWithPath(item.path);        
  851.                 if (file.exists())
  852.                 {
  853.                     var istream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
  854.                     var bstream = Components.classes["@mozilla.org/binaryinputstream;1"].createInstance(Components.interfaces.nsIBinaryInputStream);
  855.                     try{
  856.                             istream.init(file, -1, -1, false);
  857.                             bstream.setInputStream(istream);
  858.                             str = String(bstream.readBytes(bstream.available() > 4 ? 4 : bstream.available()));//only read needed bytes
  859.                     }catch(e){bpriv.LOG("BetterPrivacy: HexFootPrint error 1 " + e); return false;}
  860.                     bstream.close();
  861.                     istream.close();
  862.                     if(str && str.length >= 4)
  863.                     {
  864.                         var h = navigator.preference("extensions.bprivacy.LSOHexFootprint").split("|");//get hexfootprint
  865.                         for (var i = 0; i < 4; i++) {
  866.                             if(str.charCodeAt(i) != h[i]) //compare
  867.                                 return false;
  868.                         }
  869.                     }
  870.                 }
  871.             }catch(e){bpriv.LOG("BetterPrivacy: HexFootPrint error 2 " + e); return false;}
  872.         }
  873.         return true;
  874.     },
  875.  
  876.  
  877.  
  878.  
  879.     Lso: function(entry, ident, size, path, prot, modified)
  880.     {
  881.         this.file = entry;
  882.         this.ident = ident;
  883.         this.name = entry.leafName;
  884.         this.size = size;
  885.         this.path = path;
  886.         this.prot = prot;
  887.         this.modified = modified;
  888.         return this;
  889.     },
  890.  
  891.  
  892.  
  893.  
  894.     FindLSORoot: function(HomeDir, ExToFind)
  895.     {
  896.         if(bpriv.Stack.length > 0)
  897.             return; //important
  898.         bpriv.Stack[0] = HomeDir;
  899.         bpriv.Scan = 1;
  900.         bpriv.FindLSORootNonRecursive( ExToFind, 1);
  901.     },
  902.  
  903.  
  904.     FindLSORootNonRecursive: function(ExToFind,  done)
  905.     {
  906.         var finish = function(newdir){
  907.             bpriv.LSOTreeShow(newdir);
  908.             bpriv.Scan = 0;
  909.             bpriv.Stack = [];
  910.         }
  911.         var currentDir = bpriv.Stack.pop();
  912.         if (ExToFind.test(currentDir.leafName))
  913.         {
  914.             var Dir = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  915.             try{
  916.                   Dir.initWithPath(currentDir.path); 
  917.                   if(Dir.path && Dir.exists() && Dir.isDirectory())
  918. //                    navigator.preference("extensions.bprivacy.flashAppDir", Dir.path);
  919. //                    navigator.preference("extensions.bprivacy.DataDir", Dir);
  920.                     bpriv.prefs.setComplexValue("DataDir", Components.interfaces.nsILocalFile, Dir);
  921.                 else
  922.                     Dir = null;
  923.             }catch(e){Dir = null;}
  924.      
  925.             finish(Dir);
  926.             return;
  927.         }
  928.         done++;
  929.         var entries;
  930.         try{
  931.             entries = currentDir.directoryEntries;
  932.         }catch(e){}
  933.         while(entries && entries.hasMoreElements() && bpriv.Scan > 0)
  934.         {
  935.             var entry = entries.getNext();
  936.             entry.QueryInterface(Components.interfaces.nsIFile);
  937.             if (entry.isDirectory() && !entry.isSymlink() && !bpriv.isSpecial(entry))
  938.                 bpriv.Stack.push(entry);
  939.         }
  940.          if(bpriv.Scan > 0 && bpriv.Stack.length > 0){
  941.             //GUI
  942.             if(bpriv.getDoc().getElementById("lsoinfo")) 
  943.                 bpriv.getDoc().getElementById("lsoinfo").value = bpriv.getString("LSOFolderScan") + " ["+done+"]";
  944.             if(bpriv.getDoc().getElementById("searchFolderID"))
  945.                 bpriv.getDoc().getElementById("searchFolderID").label = bpriv.getString("abort");
  946.             //GUI-end
  947.             setTimeout( function(){bpriv.FindLSORootNonRecursive( ExToFind, done)}, 1, ExToFind, done);
  948.         }else{
  949.             if(bpriv.Scan > 0 && bpriv.getDoc().getElementById("lsoinfo")) 
  950.                 bpriv.getDoc().getElementById("lsoinfo").value = bpriv.getString("NoDirFound");
  951.             finish(bpriv.GetFlashDir(0));
  952.         }
  953.     },
  954.  
  955.  
  956.  
  957.     isSpecial: function(entry)
  958.     {
  959.         try{
  960.             return entry.isSpecial();
  961.         }catch(e){}
  962.         return false; //no avail on Mac
  963.     },
  964.  
  965.  
  966.  
  967.     RemoveFromLSOProtection: function(path)
  968.     {
  969.         var exp = new RegExp('^.*'+navigator.preference("extensions.bprivacy.FlashDirRegEx")+'(\u005c\u002f|\u005c\u005c)', 'i');
  970.         if(navigator.preference("extensions.bprivacy.alwaysReScan"))
  971.             path = path.replace(exp, "");
  972.  
  973.  
  974.         var protListarr = navigator.preference("extensions.bprivacy.protectedLSOList").split("|");
  975.         for (var x=0;x<protListarr.length;x++)
  976.         {    
  977.             var dir = protListarr[x];
  978.             if(navigator.preference("extensions.bprivacy.alwaysReScan"))
  979.                 dir = dir.replace(exp, "");
  980.             if(dir.toLowerCase() == path.toLowerCase())
  981.                 protListarr.splice(x, 1);
  982.         }
  983.         navigator.preference("extensions.bprivacy.protectedLSOList", protListarr.join("|")); 
  984.         protListarr = null;
  985.     },
  986.  
  987.  
  988.  
  989.     AddToLSOProtection: function(path)
  990.     {
  991.         var protListarr = navigator.preference("extensions.bprivacy.protectedLSOList").split("|");
  992.         for (var x=0;x<protListarr.length;x++)
  993.         {    
  994.             if(protListarr[x].toLowerCase() == path.toLowerCase()){
  995.                 protListarr = null;
  996.                 return;
  997.             }
  998.         }
  999.         protListarr.push(path);
  1000.         navigator.preference("extensions.bprivacy.protectedLSOList", protListarr.join("|")); 
  1001.         protListarr = null;
  1002.     },
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.     ToggleLSOProtection: function(mode)
  1009.     {
  1010.         var LSOTree = bpriv.getDoc().getElementById("LSOViewerTree");
  1011.         if(LSOTree.currentIndex < 0)
  1012.             return;
  1013.         var toModify = LSOTree.currentIndex;
  1014.         var path = bpriv.lsos[toModify].path;
  1015.  
  1016.         var exp = new RegExp(bpriv.lsos[toModify].file.leafName, 'i');
  1017.         path = path.replace(exp, "");
  1018.         path = path.replace(/[\\\/]$/i, "");
  1019.         if(bpriv.lsos[toModify].prot.indexOf("d") < 0){
  1020.             bpriv.AddToLSOProtection(path);
  1021.             bpriv.lsos[toModify].prot = "d";
  1022.         }else
  1023.         {
  1024.             bpriv.RemoveFromLSOProtection(path);
  1025.             bpriv.lsos[toModify].prot = bpriv.lsos[toModify].prot.replace(/d/g, "");
  1026.         }
  1027.  
  1028.         bpriv.RefreshLSOProtection();
  1029.         bpriv.updateGUI(bpriv.GetFlashDir(0), false);
  1030.         bpriv.TreeOnSelect();
  1031.     },
  1032.  
  1033.  
  1034.  
  1035.     DeleteLso: function()
  1036.     {
  1037.         var LSOTree = bpriv.getDoc().getElementById("LSOViewerTree");
  1038.         if(!bpriv.lsos[LSOTree.currentIndex])
  1039.             return;
  1040.         try{
  1041.             if(bpriv.lsos[LSOTree.currentIndex].file.exists())
  1042.                 bpriv.lsos[LSOTree.currentIndex].file.remove(false);  
  1043.             else
  1044.                 alert("This file does not exist anymore, nothing to do");
  1045.         }catch(e){alert("Error: Failed to delete that file!"); return;}
  1046.         bpriv.lsos.splice(LSOTree.currentIndex , 1);  
  1047.         LSOTree.treeBoxObject.rowCountChanged(LSOTree.currentIndex + 1 , -1);
  1048.         bpriv.updateGUI(bpriv.GetFlashDir(0), false);
  1049.         bpriv.TreeOnSelect();
  1050.         bpriv.delDirs(bpriv.GetFlashDir(0));
  1051.     },
  1052.  
  1053.  
  1054.     DeleteAllLsos: function()
  1055.     {
  1056.         var LSOTree = bpriv.getDoc().getElementById("LSOViewerTree");
  1057.         var protectedCookie = false;
  1058.         for (var x=0;x<bpriv.lsos.length;x++)
  1059.         {
  1060.             if(String(bpriv.lsos[x].prot).indexOf("d") >= 0 || String(bpriv.lsos[x].prot).indexOf("s") >= 0){
  1061.                 protectedCookie = true;
  1062.                 break;
  1063.             }
  1064.         }
  1065.         var button = 0;
  1066.         if(protectedCookie)
  1067.         {
  1068.             check = {value: false};
  1069.             var flags = bpriv.prompts.BUTTON_POS_0 * bpriv.prompts.BUTTON_TITLE_YES +
  1070.                         bpriv.prompts.BUTTON_POS_1 * bpriv.prompts.BUTTON_TITLE_NO  +
  1071.                         bpriv.prompts.BUTTON_POS_2 * bpriv.prompts.BUTTON_TITLE_CANCEL;
  1072.             button =bpriv.prompts.confirmEx(null, "BetterPrivacy", bpriv.getString("asktodeleteall"), flags, "", "", "", null, check);
  1073.             if(button == 2)
  1074.                 return;
  1075.         }
  1076.         var deleted = 0;
  1077.         for (var x=0;x<bpriv.lsos.length;x++)
  1078.         {
  1079.             protectedCookie = false;
  1080.             if(String(bpriv.lsos[x].prot).indexOf("d") >= 0 || String(bpriv.lsos[x].prot).indexOf("s") >= 0)
  1081.                 protectedCookie = true;
  1082.             try{
  1083.                 if(!(button == 1 && protectedCookie)){
  1084.                     bpriv.lsos[x].file.remove(false);
  1085.                     deleted++;
  1086.                 }
  1087.             }catch(e){}
  1088.         }
  1089.         if(deleted){
  1090.             bpriv.LSOTreeShow(bpriv.GetFlashDir(0));
  1091.             bpriv.TreeOnSelect();
  1092.             bpriv.delDirs(bpriv.GetFlashDir(0));
  1093.         }
  1094.     },
  1095.  
  1096.  
  1097.  
  1098.  
  1099.     GetRootDir: function(platform)    
  1100.     {
  1101.         switch (platform){
  1102.         case "windows":
  1103.             return(Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("AppData", Components.interfaces.nsILocalFile));
  1104.         break;
  1105.         case "mac1":
  1106.             return(Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ULibDir", Components.interfaces.nsILocalFile));
  1107.         break;
  1108.         case "mac2":
  1109.             return(Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("UsrPrfs", Components.interfaces.nsILocalFile));
  1110.         break;
  1111.         case "linux":
  1112.             //gets user-directory
  1113.             return(Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("Home", Components.interfaces.nsILocalFile));
  1114.         break;
  1115.         }
  1116.         return null;
  1117.     },
  1118.  
  1119.  
  1120.  
  1121.     GetFlashDir: function(ForceSearch)    // detection of Flash Apps directory
  1122.     {
  1123.         //ForceSearch=0: Try current preference if available (user may have set directory manually) otherwise get predifined places
  1124.         //ForceSearch=1: Ignore current preference, get predefined places (e.g. portable mode)
  1125.         //ForceSearch=2: Ignore current preference, get predefined places and if this fails do a scan (e.g. search directory)
  1126.  
  1127.         var FlashDir = null;
  1128.         var knownDir = null;
  1129.         var ExToFind = new RegExp('^'+navigator.preference("extensions.bprivacy.FlashDirRegEx")+'(\u005c\u002f|\u005c\u005c)?$', 'i');
  1130.  
  1131.         var Dir = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  1132.         if(ForceSearch < 1)
  1133.         {
  1134.             var currentDir;
  1135.             try{
  1136.                 currentDir = bpriv.prefs.getComplexValue("DataDir", Components.interfaces.nsILocalFile);
  1137.             }catch(e){}
  1138.  
  1139.             if (currentDir)
  1140.             {
  1141.                 try{
  1142.                       if(currentDir.path && currentDir.exists() && currentDir.isDirectory())
  1143.                         knownDir = currentDir;
  1144.                 }catch(e){}
  1145.             }
  1146.  
  1147.         }
  1148.  
  1149.         //scan
  1150.         if(ForceSearch > 0 && !knownDir)
  1151.         {
  1152.             try{
  1153.                 //windows
  1154.                 if(bpriv.GetRootDir("windows") && bpriv.GetRootDir("windows").exists() && bpriv.GetRootDir("windows").isDirectory())
  1155.                 {
  1156.                     FlashDir = bpriv.GetRootDir("windows");
  1157.                     FlashDir.append("Roaming");
  1158.                     FlashDir.append("Macromedia");
  1159.                     if(FlashDir.exists() && FlashDir.isDirectory())
  1160.                         knownDir = FlashDir;
  1161.                     if(!knownDir)
  1162.                     {
  1163.                         FlashDir = bpriv.GetRootDir("windows");
  1164.                         FlashDir.append("Macromedia");
  1165.                         if(FlashDir.exists() && FlashDir.isDirectory())
  1166.                             knownDir = FlashDir;
  1167.                     }
  1168.                     if(!knownDir && (!navigator.preference("extensions.bprivacy.noAutoScan") || ForceSearch == 2))
  1169.                         bpriv.FindLSORoot(bpriv.GetRootDir("windows"), ExToFind);
  1170.                 }
  1171.             }catch(e){}
  1172.         }
  1173.         if(ForceSearch > 0 && !knownDir)
  1174.         {
  1175.             try{
  1176.                 //mac1
  1177.                 if(bpriv.GetRootDir("mac1") && bpriv.GetRootDir("mac1").exists() && bpriv.GetRootDir("mac1").isDirectory())
  1178.                 {
  1179.                     FlashDir = bpriv.GetRootDir("mac1");
  1180.                     FlashDir.append("Preferences");
  1181.                     FlashDir.append("Macromedia");
  1182.                     if(FlashDir.exists() && FlashDir.isDirectory())
  1183.                         knownDir = FlashDir;
  1184.  
  1185.                     if(!knownDir && (!navigator.preference("extensions.bprivacy.noAutoScan") || ForceSearch == 2))
  1186.                         bpriv.FindLSORoot(bpriv.GetRootDir("mac1"), ExToFind);
  1187.                 }
  1188.             }catch(e){}
  1189.         }
  1190.         if(ForceSearch > 0 && !knownDir)
  1191.         {
  1192.             try{
  1193.                 //mac2
  1194.                 if(bpriv.GetRootDir("mac2") && bpriv.GetRootDir("mac2").exists() && bpriv.GetRootDir("mac2").isDirectory())
  1195.                 {
  1196.                     FlashDir = bpriv.GetRootDir("mac2");
  1197.                     FlashDir.append("Macromedia");
  1198.                     if(FlashDir.exists() && FlashDir.isDirectory())
  1199.                         knownDir = FlashDir;
  1200.                     if(!knownDir && (!navigator.preference("extensions.bprivacy.noAutoScan") || ForceSearch == 2))
  1201.                         bpriv.FindLSORoot(bpriv.GetRootDir("mac2"), ExToFind);
  1202.                 }
  1203.             }catch(e){}
  1204.         }
  1205.         if(ForceSearch > 0 && !knownDir)
  1206.         {
  1207.             try{
  1208.                 //linux
  1209.                 if(bpriv.GetRootDir("linux") && bpriv.GetRootDir("linux").exists() && bpriv.GetRootDir("linux").isDirectory())
  1210.                 {
  1211.                     FlashDir = bpriv.GetRootDir("linux");
  1212.                     FlashDir.append(".macromedia");
  1213.                     if(FlashDir.exists() && FlashDir.isDirectory())
  1214.                         knownDir = FlashDir;
  1215.                     if(!knownDir && (!navigator.preference("extensions.bprivacy.noAutoScan") || ForceSearch == 2))
  1216.                         bpriv.FindLSORoot(bpriv.GetRootDir("linux"), ExToFind);
  1217.                 }
  1218.             }catch(e){}
  1219.         }
  1220.  
  1221.  
  1222.         try{
  1223.               if(knownDir.path && knownDir.exists() && knownDir.isDirectory())
  1224.             {
  1225.                 bpriv.prefs.setComplexValue("DataDir", Components.interfaces.nsILocalFile, knownDir);
  1226.                 return knownDir;
  1227.             }
  1228.         }catch(e){}     
  1229.  
  1230.         return null;
  1231.     },
  1232.  
  1233.  
  1234.  
  1235.     SortLSOView: function(col)
  1236.     {
  1237.         var LSOTree = bpriv.getDoc().getElementById("LSOViewerTree");
  1238.         if(!LSOTree)
  1239.             return;
  1240.         bpriv.SortTable(col, bpriv.lsos, LSOTree);
  1241.     },
  1242.  
  1243.  
  1244.  
  1245.     SortTable: function(column, table, tree) {
  1246.         var columnName = column;
  1247.         if(!column)
  1248.         {
  1249.             if(tree.getAttribute("sortResource"))
  1250.                 columnName = tree.getAttribute("sortResource");
  1251.             else
  1252.                 return;
  1253.         }
  1254.         var order = tree.getAttribute("sortDirection") == "ascending" ? 1 : -1;
  1255.         //if it's already sorted by that column, reverse sort
  1256.         if (tree.getAttribute("sortResource") == column) 
  1257.             order *= -1;
  1258.         columnSort = function compare(a, b)
  1259.         {
  1260.             if (bpriv.prepareForComparison(a[columnName]) > bpriv.prepareForComparison(b[columnName])) return 1 * order;
  1261.             if (bpriv.prepareForComparison(a[columnName]) < bpriv.prepareForComparison(b[columnName])) return -1 * order;
  1262.             return 0;
  1263.         }
  1264.         table.sort(columnSort);
  1265.  
  1266.         //setting these will make the sort option persist
  1267.         tree.setAttribute("sortDirection", order == 1 ? "ascending" : "descending");
  1268.         tree.setAttribute("sortResource", columnName);
  1269.         tree.view = bpriv.treeView;
  1270.  
  1271.         //set the appropriate attributes to show to indicator
  1272.         var cols = tree.getElementsByTagName("treecol");
  1273.         for (var i = 0; i < cols.length; i++) {
  1274.             cols[i].removeAttribute("sortDirection");
  1275.         }
  1276.         bpriv.getDoc().getElementById(columnName).setAttribute("sortDirection", order == 1 ? "ascending" : "descending");
  1277.  
  1278.         //redraw tree
  1279.         tree.treeBoxObject.invalidate();
  1280.  
  1281.         //get old selection
  1282.         tree.view.selection.select(-1);
  1283.         if(bpriv.selected != null)
  1284.         {
  1285.             for (var i = 0; i < table.length; i++)
  1286.             {
  1287.                 if (table[i].path == bpriv.selected)
  1288.                 {
  1289.                     tree.view.selection.select(i);
  1290.                     //scroll into view
  1291.                     tree.treeBoxObject.ensureRowIsVisible(i);
  1292.                     break;
  1293.                 }
  1294.             }
  1295.  
  1296.         }
  1297.  
  1298.     },
  1299.  
  1300.  
  1301.  
  1302.     //prepares an object for easy comparison against another. for strings, lowercases them
  1303.     prepareForComparison: function(o) {
  1304.         if (typeof o == "string") 
  1305.             return o.toLowerCase();
  1306.         return o;
  1307.     },
  1308.  
  1309.  
  1310.  
  1311.     showBetterPrivacy: function(){
  1312.         var enumerator = bpriv.wm.getEnumerator("");
  1313.         var win;
  1314.         while(enumerator && enumerator.hasMoreElements()) {
  1315.             awin = enumerator.getNext();
  1316.             if(awin && awin.document && awin.document.getElementById("bprivprefpane")){
  1317.                 win = awin;
  1318.                 break;
  1319.             }
  1320.         }
  1321.         if(!win)
  1322.             win = window.openDialog('chrome://bp/content/bp.xul', '_blank', 'chrome=yes, resizable=yes, centerscreen=yes', 1);
  1323.         win.focus();
  1324.     },
  1325.  
  1326.  
  1327.  
  1328.     getString: function(strID){
  1329.         var str = "";
  1330.         try{
  1331.             str = bpriv.getDoc().getElementById("strBundle").getString(strID);
  1332.         }catch(e){}
  1333.         return str;
  1334.     },
  1335.  
  1336.  
  1337.     hashString: function(str){
  1338.         var converter =
  1339.           Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].
  1340.             createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
  1341.         
  1342.         // we use UTF-8 here, you can choose other encodings.
  1343.         converter.charset = "UTF-8";
  1344.         // result is an out parameter,
  1345.         // result.value will contain the array length
  1346.         var result = {};
  1347.         // data is an array of bytes
  1348.         var data = converter.convertToByteArray(str, result);
  1349.         var ch = Components.classes["@mozilla.org/security/hash;1"]
  1350.                            .createInstance(Components.interfaces.nsICryptoHash);
  1351.         ch.init(ch.MD5);
  1352.         ch.update(data, data.length);
  1353.         var hash = ch.finish(false);
  1354.         
  1355.         // return the two-digit hexadecimal code for a byte
  1356.         function toHexString(charCode)
  1357.         {
  1358.           return ("0" + charCode.toString(16)).slice(-2);
  1359.         }
  1360.         
  1361.         // convert the binary hash data to a hex string.
  1362.         var s = [toHexString(hash.charCodeAt(i)) for (i in hash)].join("");
  1363.         // s now contains your hash in hex: should be
  1364.         return s;
  1365.     },
  1366.  
  1367.  
  1368.  
  1369.     onKeyCode: function()
  1370.     {
  1371.         bpriv.prepareDelLSO(0, null);
  1372.     },
  1373.  
  1374.  
  1375.  
  1376.    addSanitizeItem: function () {
  1377.         if(!navigator.preference("extensions.bprivacy.AutoDelLSOnExitMode"))
  1378.             return;
  1379.         if (typeof Sanitizer != 'function')
  1380.             return;
  1381.         // Sanitizer will execute this
  1382.         Sanitizer.prototype.items["extensions-betterprivacy"] = 
  1383.         {
  1384.             clear : function(){
  1385.                 try{
  1386.                     bpriv.sanitize(window.document);
  1387.                 }catch(e){}
  1388.             },
  1389.             get canClear(){
  1390.                 return true;
  1391.             }
  1392.       }
  1393.    },
  1394.  
  1395.  
  1396.  
  1397.    addSanitizeMenuItem: function () {
  1398.         if(!navigator.preference("extensions.bprivacy.AutoDelLSOnExitMode"))
  1399.             return;
  1400.         var prefs = document.getElementsByTagName("preferences")[0];
  1401.         if(!prefs.hasChildNodes())
  1402.             return;
  1403.         var id = prefs.lastChild.getAttribute("id");
  1404.         if (prefs && id) 
  1405.         {
  1406.             var prefName;
  1407.             if (id.indexOf("privacy.cpd.") != -1) 
  1408.             {
  1409.                 prefName = "privacy.cpd.extensions-betterprivacy";
  1410.                 var oldPrefName = "privacy.item.extensions-betterprivacy";
  1411.                 //if an old pref exists then use it
  1412.                 if (!navigator.preference(prefName) && navigator.preference(oldPrefName))
  1413.                     navigator.preference(prefName, navigator.preference(oldPrefName));
  1414.             }
  1415.             else if (id.indexOf("privacy.") != -1) 
  1416.             {
  1417.                 prefName = "privacy.item.extensions-betterprivacy";
  1418.             }
  1419.             else
  1420.                 return;
  1421.  
  1422.             var pref = document.createElement("preference");
  1423.             pref.setAttribute("id", prefName);
  1424.             pref.setAttribute("name", prefName);
  1425.             pref.setAttribute("type", "bool");
  1426.             prefs.appendChild(pref);
  1427.  
  1428.             var item;
  1429.             var itemList = document.getElementById("itemList");
  1430.             if (itemList)
  1431.                 item = itemList.lastChild;
  1432.             else 
  1433.             {
  1434.                 item = document.getElementsByTagName("checkbox");
  1435.                 item = item[item.length - 1];
  1436.             }
  1437.             
  1438.             var check = document.createElement(itemList ? "listitem" : "checkbox");
  1439.             check.setAttribute("label", "Flash Cookies");
  1440.             check.setAttribute("preference", prefName);
  1441.             
  1442.             if(itemList) 
  1443.             {
  1444.                 check.setAttribute("type", "checkbox");
  1445.                 itemList.appendChild(check);
  1446.             }
  1447.             else
  1448.             {
  1449.                 if(item.parentNode.childNodes.length == 2)
  1450.                 {
  1451.                     var row = document.createElement("row");
  1452.                     item.parentNode.parentNode.appendChild(row);
  1453.                     row.insertBefore(check, null);
  1454.                 }else
  1455.                     item.parentNode.insertBefore(check, null);
  1456.             }
  1457.             if (typeof(gSanitizePromptDialog) == "object") 
  1458.             {
  1459.                 pref.setAttribute("readonly", "true");
  1460.                 check.setAttribute("onsyncfrompreference", "return gSanitizePromptDialog.onReadGeneric();");
  1461.             }
  1462.       }
  1463.    },
  1464.  
  1465.  
  1466.    sanitize: function (doc) {
  1467.         var ticks = 0;
  1468.         if(doc.getElementById("sanitizeDurationChoice"))
  1469.         {
  1470.             var idx = doc.getElementById("sanitizeDurationChoice").selectedIndex;
  1471.             var currentTime = new Date();
  1472.             switch(idx)
  1473.             {
  1474.             case 0: //1 hour
  1475.               ticks = 3600000;
  1476.               break;
  1477.             case 1: //2 hours
  1478.               ticks = 7200000;
  1479.               break;
  1480.             case 2: //4 hours
  1481.               ticks = 14400000;
  1482.               break;
  1483.             case 3: //today
  1484.               ticks = (currentTime.getHours() * 60 * 60 * 1000) + (currentTime.getMinutes() * 60 * 1000) + (currentTime.getSeconds() * 1000);
  1485.               break;
  1486.             }
  1487.         }
  1488.         //clear LSO data
  1489.         bpriv.prepareDelLSO(0, ticks);
  1490.  
  1491.    },
  1492.  
  1493.  
  1494.     extopened: function()
  1495.     {
  1496.         var isExtensionsWin = document.getElementById("extensionsStrings");
  1497.         if (isExtensionsWin) //extensions manager
  1498.         {
  1499.             eval("gExtensionsViewController.commands.cmd_options ="+gExtensionsViewController.commands.cmd_options.toString().replace(
  1500.             'var optionsURL = aSelectedItem.getAttribute("optionsURL");',
  1501.             '$& \ if (bpriv.isOptionsURL(optionsURL)) return;'
  1502.             ));
  1503.         }
  1504.     },
  1505.  
  1506.     isOptionsURL: function(url) {
  1507.         if (url != "chrome://bp/content/bp.xul")
  1508.             return false;
  1509.         var gWindowManager =  Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
  1510.         var aBrowser = gWindowManager.getMostRecentWindow("navigator:browser");
  1511.         if (!aBrowser)
  1512.         {
  1513.           var rwin = gWindowManager.getMostRecentWindow("mozilla:betterprivacy");
  1514.           if(rwin)
  1515.              rwin.close();
  1516.           bpriv.prompts.alert(window, "BetterPrivacy", "BetterPrivacy requires at least one open browser window!");
  1517.         }
  1518.         else
  1519.             bpriv.showBetterPrivacy(); 
  1520.         return true;
  1521.     },
  1522.  
  1523.  
  1524.  
  1525.  
  1526.  
  1527.  
  1528.  
  1529.  
  1530. };